/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.icode.rmi;

import com.icode.entities.Modules;
import com.icode.utils.HibernateUtil;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Hot_Girls
 */
public class ModuleDAO extends UnicastRemoteObject implements IModules{
    public ModuleDAO() throws RemoteException{
        super();
    }

    @Override
    public List<Modules> fetchAll() throws RemoteException {
        Session s = HibernateUtil.getSession();
        return s.createQuery("from Modules").list();
    }

    @Override
    public void save(Modules u) throws RemoteException {
        Session s = HibernateUtil.getSession();
        Transaction tran = s.beginTransaction();
        s.save(u);
        tran.commit();
    }

    @Override
    public void update(Modules u) throws RemoteException {
        Session s = HibernateUtil.getSession();
        Transaction tran = s.beginTransaction();
        s.update(u);
        tran.commit();
    }

    @Override
    public void delete(Modules u) throws RemoteException {
        Session s = HibernateUtil.getSession();
        Transaction tran = s.beginTransaction();
        s.delete(u);
        tran.commit();
    }

    @Override
    public Modules fetchById(Integer id) throws RemoteException {
        Session s = HibernateUtil.getSession();
        Modules m = (Modules) s.get(Modules.class, id);
        return m;
    }
    
}
